package com.bitin.module.misc.api;

import com.bitin.module.misc.domain.entity.Level;
import com.bitin.module.misc.domain.entity.Region;
import com.bitin.module.misc.service.RegionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;

/**
 * @author Mr.Lu
 * @since 2024/7/25 14:53
 */
@Controller
public class IndexController {

    private final RegionService regionService;

    public IndexController(RegionService regionService) {
        this.regionService = regionService;
    }

    @ResponseBody
    @GetMapping("/sync/data")
    public List<Region> synchrodata(String keywords, String subdistrict, String extensions) throws IOException {
        return regionService.copy(keywords, subdistrict, extensions);
    }

    @ResponseBody
    @GetMapping("/syncs/data")
    public void syncs(Level level) throws IOException {
        System.err.println(level);
        regionService.syncs(level);
    }
}
